package com.qin.mall.controller.productcontroller;

import com.qin.mall.openfeign.product.ProductFeigin;
import com.qin.mall.common.api.CommonResult;
import com.qin.mall.common.api.MyBatisPlusPage;
import com.qin.mall.domain.PmsProduct;
import com.qin.mall.dto.PmsProductParam;
import com.qin.mall.dto.PmsProductQueryParam;
import com.qin.mall.dto.PmsProductResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品管理
 * @author Leisure
 * create 2022 2022/11/19 18:48
 **/
@RestController
@RequestMapping("/product")
public class UserProductController {
    
    @Autowired
    private ProductFeigin productFeigin;

    //创建商品
    @PostMapping("/create")
    public CommonResult create(@RequestBody PmsProductParam productParam){
        CommonResult result = productFeigin.create(productParam);
        return result;
    }

    //根据商品编号获取更新前的信息,和其他关联的所有的信息
    @GetMapping("/updateInfo/{id}")
    public CommonResult<PmsProductResult> getUpdateInfo(@PathVariable Long id){
        CommonResult<PmsProductResult> updateInfo = productFeigin.getUpdateInfo(id);
        return updateInfo;
    }

    //更新商品
    @PostMapping("/update/")
    public CommonResult updateById(@RequestParam("id") Long id,
                                   @RequestBody PmsProductParam productParam){
        CommonResult commonResult = productFeigin.updateById(id,productParam);
        return commonResult;
    }

    //分页查询商品
    @GetMapping("/list")
    @ResponseBody
    public CommonResult<MyBatisPlusPage<PmsProduct>> getList(
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSiz,
            PmsProductQueryParam productQueryParam){
        CommonResult<MyBatisPlusPage<PmsProduct>> listAll = productFeigin.getListAll(pageNum, pageSiz, productQueryParam);
        return listAll;
    }

    //根据商品名称或者货号模糊查询
    @GetMapping("/simpleList")
    public CommonResult<List<PmsProduct>> getList(@RequestParam("keyword") String keyword){
        CommonResult<List<PmsProduct>> list = productFeigin.getList(keyword);
        return list;
    }

    //批量修改审核状态
    @PostMapping("/update/verifyStatus")
    public CommonResult updateStatus(@RequestParam("verifyStatus") Integer verifyStatus,
                                     @RequestParam("detail") String detail,
                                     @RequestBody List<Long> ids){
        CommonResult result = productFeigin.updateStatus(verifyStatus, detail, ids);
        return result;
    }

    //批量修改商品上下架状态
    @PostMapping("/update/publishStatus")
    @ResponseBody
    public CommonResult updatepublishStatus(@RequestParam("publishStatus") Integer publishStatus,
                                            @RequestParam("ids") List<Long> ids){
        CommonResult result = productFeigin.updatepublishStatus(publishStatus, ids);
        return result;
    }

    //批量修改商品推荐状态
    @PostMapping("/update/recommendStatus")
    public CommonResult updateRecommendStatus(@RequestParam("recommendStatus") Integer recommendStatus,
                                              @RequestParam("ids") List<Long> ids){
        CommonResult result = productFeigin.updateRecommendStatus(recommendStatus, ids);
        return result;
    }

    //批量修改新品状态
    @PostMapping("/update/newStatus")
    @ResponseBody
    public CommonResult updateNewStatus(@RequestParam("newStatus") Integer newStatus,
                                        @RequestParam("ids") List<Long> ids){
        CommonResult result = productFeigin.updateNewStatus(newStatus, ids);
        return result;
    }

    //批量删除商品
    @PostMapping("/update/deleteStatus")
    @ResponseBody
    public CommonResult updateDeleteStatus(@RequestParam("deleteStatus") Integer deleteStatus,
                                           @RequestParam("ids") List<Long> ids){
        CommonResult result = productFeigin.updateDeleteStatus(deleteStatus, ids);
        return result;
    }
}
